﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<CRM.Database.Model.RolesAccesses>>" %>

<%@ Import Namespace="CRM.Database.Model" %>
<%@ Import Namespace="CRM.Resourses" %>
<%@ Import Namespace="System.Threading" %>

<% Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdRolesAccesses";
                                        settings.KeyFieldName = "IdRolesAccess";
                                        settings.CallbackRouteValues =
                                            new { Controller = "Dictionaries", Action = "RolesAccessesPartial" };
                                        settings.SettingsPager.PageSize = 20;
                                       
                                        //
                                        //Добавление комбобоксов
                                        //
                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdRole";
                                            column.Caption = Resourses.Roles;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;

                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var col = new RolesCollection();

                                                comboBoxProperties.DataSource =
                                                    col.RolesList;
                                                comboBoxProperties.TextField = "RoleNameLocalized";
                                                comboBoxProperties.ValueField = "IdRole";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        //конец комбобокса

                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdControllersAndAction";
                                            column.Caption = Resourses.RolesAccessAction;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;

                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var col = new ControllersAndActionsCollection();
                                                comboBoxProperties.DataSource = col.ControllersAndActionsList;

                                                comboBoxProperties.TextField = "ControllerAndAction";
                                                comboBoxProperties.ValueField = "IdControllersAndAction";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });


                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.UserLoginModified;
                                            column.FieldName = "IdUserLoginModified";
                                            column.ReadOnly = true;
                                        });
                                        
                                        //
                                        //Добавление редактирования
                                        //
                                        settings.CommandColumn.Visible = true;
                                        settings.CommandColumn.NewButton.Visible = true;
                                        settings.CommandColumn.DeleteButton.Visible = true;
                                        settings.CommandColumn.EditButton.Visible = true;
                                        settings.SettingsBehavior.ConfirmDelete = true;
                                        settings.Settings.ShowFilterRow = true;
                                        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Dictionaries", Action = "RolesAccessesPartialUpdate" };
                                        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Dictionaries", Action = "RolesAccessesPartialAdd" };
                                        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Dictionaries", Action = "RolesAccessesPartialDelete" };
                                        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
                                        settings.Width = Unit.Percentage(100);
                                    })
       .Bind(Model).GetHtml();
%>


